import { WorldState } from "GameLoop/WorldState/worldstate";
import { EventChecker } from "./CheckFunction/Room/EventChecker";
import { StateUpdater } from "./CheckFunction/Room/StateUpdater";
 
/*@profile*/
export class RoomEvent implements IEventCheck<IEventChecker,Room>
{
    _tickStart: Record<number, IEventChecker[]>={};
    _tickEnd: Record<number, IEventChecker[]>={};
    _world!:WorldState;
    _eventTrigger!:TEventEmitter<TEventTypes>;
     
    init( _world:WorldState,_eventTrigger:TEventEmitter<TEventTypes>)
    {
        this._world = _world;
        this._eventTrigger = _eventTrigger
    }
    
    public initEvent()
    {
        this._tickStart={
            0:[
                StateUpdater.checkUpdateRoomScan,
                EventChecker.checkInitRoom  // 检测初始化房间
            ],
            1:[
                EventChecker.checkMyRoomLose,
                 StateUpdater.updateCreepRoleStatus,
                StateUpdater.updateEntity,
                StateUpdater.checkResourceStats,
                EventChecker.checkTick,
                EventChecker.checkLevelUp,  // 检测主房事件
                EventChecker.checkEnergyCapacityIncress,
                EventChecker.checkRepair,
                EventChecker.checkFillAnyStore,
                EventChecker.checkDefend,
                EventChecker.checkBuild,
                EventChecker.checkPowerTask,
                EventChecker.checkBuildComplete
                
            ],
            3:[
                // EventChecker.checkRepair, 外矿不修理了
                EventChecker.checkBuild,
                EventChecker.checkReserve,
                EventChecker.checkDefendMine,
                EventChecker.checkBeAttack,
                EventChecker.checkTransferOutMine,
                EventChecker.checkRemoveMine
            ],
            5:[
                StateUpdater.checkUpdateRoomScan,
                EventChecker.checkHallwayHarvest,
              
            ],
            6:[
                 
                // EventChecker.checkRepair,外矿不修理了
                EventChecker.checkBuild,
                EventChecker.checkPauseRoomTask,
                EventChecker.checkBeAttack,
                EventChecker.checkMinerial,
                EventChecker.checkTransferOutMine
            ]
        }

        this._tickEnd={
            1:[
                StateUpdater.checkUpdateRoomHistory,
                
            ]
        }
    }
    public tickStart(room:Room)
    {
       // this._world.Station.tryRegisterRoom(room.name);

        if(this._tickStart[room.getType()])
        {
            
            for(const e of this._tickStart[room.getType()])
            {
                e(this._world,room as Required<Room>,this._eventTrigger);
            }
        }
    }
    public tickEnd(room:Room)
    {
        if(this._tickEnd[room.getType()])
        {
            
            for(const e of this._tickEnd[room.getType()])
            {
                e(this._world,room as Required<Room>,this._eventTrigger);
            }
        }
    }
}